package demo10.iterator.dinermerger;

/**
 * 餐厅菜单的迭代器
 * */
public class DinerMenuIterator implements Iterator{
	MenuItem[] items;
	int position = 0;//记录当前数组遍历的位置
 
	public DinerMenuIterator(MenuItem[] items) {//构造器参入菜单数组
		this.items = items;
	}
 
	//返回下一个
	@Override
	public MenuItem next() {
		MenuItem menuItem = items[position];
		position = position + 1;
		return menuItem;
	}
 //判断数组是否还有元素
	@Override
	public boolean hasNext() {
		if (position >= items.length || items[position] == null) {
			return false;
		} else {
			return true;
		}
	}
}
